﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Main.Master" AutoEventWireup="true" CodeBehind="Product.aspx.cs" Inherits="DevExpressWebApplication1.Module.PD.Product" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <script type="text/javascript">
        function openAdd() {
            hdfProductID.Set("ProId", -1);
            ClearData();
            popupAddEdit.Show();
        }

        function EditSupplier() {
            // var key = gvCustomer.GetRowKey(gvCustomer.GetFocusedRowIndex());
            var index = gvProduct.GetFocusedRowIndex();
            cbAddEdit.PerformCallback('Edit;' + index);
            popupAddEdit.Show();
        }

        function ClearData() {
            txtName.SetValue('');
            txtCode.SetValue('');
            txtBuyPrice.SetValue('');
            txtSellPrice.SetValue('');
            txtDescription.SetValue('');
            cbbCategory.SetText('');
        }
        function SaveComplete(s, e) {

            if (e.result != "") {
                var check = e.result;
                if (check == "Success") {
                    ClearData();
                    popupAddEdit.Hide();
                    gvProduct.PerformCallback();
                    alert("Thành công");
                } else if (check == "SuccessAndNew") {
                    New();
                }
                else {
                    alert("Thất bại");
                }
            }
        }
    </script>
    <div class="span10">
        <dx:ASPxButton runat="server" ID="btnAdd" Text="Add" Theme="DevEx" UseSubmitBehavior="False" AutoPostBack="False">
            <ClientSideEvents Click="function(s,e){openAdd()}" />
        </dx:ASPxButton>
    </div>
    <div class="span10">
        <dx:ASPxGridView ID="gvProduct" ClientInstanceName="gvProduct" OnCustomCallback="gvProduct_CustomCallback" ClientIDMode="Static"
            Width="100%" runat="server" KeyFieldName="product_id" AutoGenerateColumns="False" DataSourceID="dsProduct" Theme="DevEx">
            <ClientSideEvents RowDblClick="function(s,e){ EditSupplier() }" />
            <Columns>
                <dx:GridViewDataTextColumn FieldName="product_id" VisibleIndex="0" ReadOnly="True">
                    <EditFormSettings Visible="False" />
                </dx:GridViewDataTextColumn>
                <dx:GridViewDataTextColumn FieldName="code" VisibleIndex="1">
                </dx:GridViewDataTextColumn>
                <dx:GridViewDataTextColumn FieldName="product_name" VisibleIndex="2">
                </dx:GridViewDataTextColumn>
                <dx:GridViewDataTextColumn FieldName="category_id" VisibleIndex="3" Visible="false">
                </dx:GridViewDataTextColumn>
                <dx:GridViewDataTextColumn FieldName="price" VisibleIndex="4">
                </dx:GridViewDataTextColumn>
                <dx:GridViewDataTextColumn FieldName="buy_price" VisibleIndex="5">
                </dx:GridViewDataTextColumn>
                <dx:GridViewDataTextColumn FieldName="description" VisibleIndex="6">
                </dx:GridViewDataTextColumn>
                <dx:GridViewDataTextColumn FieldName="category_name" VisibleIndex="7">
                </dx:GridViewDataTextColumn>
            </Columns>
            <SettingsBehavior AllowFocusedRow="True" />
        </dx:ASPxGridView>
    </div>
    <asp:SqlDataSource ID="dsProduct" runat="server" ConnectionString="<%$ ConnectionStrings:PPL_ERPConnectionString %>" SelectCommand="sp_Product_Select" SelectCommandType="StoredProcedure"></asp:SqlDataSource>
    <dx:ASPxPopupControl ID="popupAddEdit" runat="server" CssFilePath="~/App_Themes/Aqua/{0}/styles.css"
        CssPostfix="Aqua" SpriteCssFilePath="~/App_Themes/Aqua/{0}/sprite.css" ClientInstanceName="popupAddEdit"
        HeaderText="Quản lý NCC" PopupHorizontalAlign="WindowCenter" PopupVerticalAlign="WindowCenter" Theme="DevEx"
        EnableClientSideAPI="True" Width="650px" Height="200px">
        <%-- PopupElementID="divPotential" --%>
        <ContentCollection>
            <dx:PopupControlContentControl ID="PopupControlContentControl6" runat="server" SupportsDisabledAttribute="True">
                <div style="width: 100%">
                    <dx:ASPxCallbackPanel ID="cbAddEdit" ClientInstanceName="cbAddEdit" OnCallback="cbAddEdit_Callback" runat="server" Width="100%">
                        <PanelCollection>
                            <dx:PanelContent>
                                <dx:ASPxHiddenField ID="hdfProductID" ClientInstanceName="hdfProductID" runat="server" />
                                <table width="100%">
                                    <tr>
                                        <td style="width: 20%">Sản phẩm
                                        </td>
                                        <td style="width: 30%">
                                            <dx:ASPxTextBox ID="txtName" ClientInstanceName="txtName" runat="server" Theme="DevEx"></dx:ASPxTextBox>
                                        </td>
                                        <td style="width: 20%">Mã sản phẩm
                                        </td>
                                        <td style="width: 30%">
                                            <dx:ASPxTextBox ID="txtCode" ClientInstanceName="txtCode" runat="server" Theme="DevEx"></dx:ASPxTextBox>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>Giá mua 
                                        </td>
                                        <td>
                                            <dx:ASPxSpinEdit ID="txtBuyPrice" ClientInstanceName="txtBuyPrice" runat="server" Height="21px" Theme="DevEx" Number="0">
                                                <SpinButtons ShowIncrementButtons="false" />
                                            </dx:ASPxSpinEdit>
                                        </td>
                                        <td>Giá bán
                                        </td>
                                        <td>
                                            <dx:ASPxSpinEdit ID="txtSellPrice" ClientInstanceName="txtSellPrice" runat="server" Height="21px" Theme="DevEx" Number="0">
                                                <SpinButtons ShowIncrementButtons="false" />
                                            </dx:ASPxSpinEdit>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>Ghi chú
                                        </td>
                                        <td>
                                            <dx:ASPxTextBox ID="txtDescription" ClientInstanceName="txtDescription" runat="server" Theme="DevEx"></dx:ASPxTextBox>
                                        </td>
                                        <td>Nhóm sản phẩm
                                        </td>
                                        <td>
                                            <dx:ASPxComboBox ID="cbbCategory" runat="server" ClientIDMode="AutoID" DataSourceID="dsCategory"
                                                IncrementalFilteringMode="Contains" LoadingPanelImagePosition="Top" ShowShadow="False"
                                                TextField="category_name" ValueField="category_id" ValueType="System.Int32"
                                                ClientInstanceName="cbbCategory" Width="100%" TabIndex="4" Theme="DevEx">
                                                <ButtonStyle BackColor="Transparent">
                                                    <Paddings Padding="0px" />
                                                    <BackgroundImage ImageUrl="0" />
                                                    <Border BorderStyle="None" />
                                                </ButtonStyle>
                                            </dx:ASPxComboBox>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td colspan="4">
                                            <dx:ASPxButton ID="ASPxButton1" runat="server" Text="Cập nhật" UseSubmitBehavior="False" AutoPostBack="False">
                                                <ClientSideEvents Click="function(s,e){ cpReloadGrid.PerformCallback(); }" />
                                            </dx:ASPxButton>
                                        </td>
                                    </tr>
                                </table>
                            </dx:PanelContent>
                        </PanelCollection>
                    </dx:ASPxCallbackPanel>
                </div>
            </dx:PopupControlContentControl>
        </ContentCollection>
    </dx:ASPxPopupControl>
    <asp:SqlDataSource ID="dsCategory" runat="server" ConnectionString="<%$ ConnectionStrings:PPL_ERPConnectionString %>" SelectCommand="sp_Category_Select" SelectCommandType="StoredProcedure"></asp:SqlDataSource>
     <dx:ASPxCallback ID="cpReloadGrid" ClientInstanceName="cpReloadGrid" runat="server"
        OnCallback="cpReloadGrid_Callback">
        <ClientSideEvents CallbackComplete="function(s,e){SaveComplete(s,e);}" />
    </dx:ASPxCallback>
</asp:Content>
